/*
 * ISerializable.cpp
 *
 */

#include "ISerializable.h"

SerializationException::SerializationException(const std::string& msg) throw() {
	this->msg = msg;
}

const char* SerializationException::what() const throw() {
	return msg.c_str();
}

TiXmlElement* ISerializable::NewField(const char* name, const char* value) {
	TiXmlText* dataNode = new TiXmlText(value);
	TiXmlElement* fieldNode = new TiXmlElement(name);
	fieldNode->LinkEndChild(dataNode);
	return fieldNode;
}

const char* ISerializable::GetField(TiXmlElement* elem, const char* name) {
	TiXmlHandle hInfo(elem);
	TiXmlText* text = hInfo.FirstChild(name).FirstChild().ToText();
	if (text)
		return text->Value();
	else
		throw SerializationException("Access violation");
}
